From 55fd3a762c4e4addc3716b6e9e1c1a6622ed7842 Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Wed, 12 Nov 2014 18:20:35 -0500 Subject: [PATCH] GtkCssProvider: Factor out a function Move finding the gtk.css file into its own function. We will make this more complicated in the near future. --- gtk/gtkcssprovider.c | 84 ++++++++++++++++++++++++-------------------- 1 file changed, 46 insertions(+), 38 deletions(-) diff --git a/gtk/gtkcssprovider.c b/gtk/gtkcssprovider.c index b5b9a2e168..8b495d219b 100644 --- a/gtk/gtkcssprovider.c +++ b/gtk/gtkcssprovider.c @@ -2956,6 +2956,50 @@ _gtk_css_provider_get_theme_dir (void) return path; } +static gchar * +_gtk_css_find_theme (const gchar *name, + const gchar *variant) +{ + gchar *subpath; + gchar *path; + + if (variant) + subpath = g_strdup_printf ("gtk-3.0" G_DIR_SEPARATOR_S "gtk-%s.css", variant); + else + subpath = g_strdup ("gtk-3.0" G_DIR_SEPARATOR_S "gtk.css"); + + /* First look in the user's config directory */ + path = g_build_filename (g_get_user_data_dir (), "themes", name, subpath, NULL); + if (!g_file_test (path, G_FILE_TEST_EXISTS)) + { + g_free (path); + /* Next look in the user's home directory + */ + path = g_build_filename (g_get_home_dir (), ".themes", name, subpath, NULL); + if (!g_file_test (path, G_FILE_TEST_EXISTS)) + { + gchar *theme_dir; + + g_free (path); + + /* Finally, try in the default theme directory */ + theme_dir = _gtk_css_provider_get_theme_dir (); + path = g_build_filename (theme_dir, name, subpath, NULL); + g_free (theme_dir); + + if (!g_file_test (path, G_FILE_TEST_EXISTS)) + { + g_free (path); + path = NULL; + } + } + } + + g_free (subpath); + + return path; +} + /** * _gtk_css_provider_load_named: * @provider: a #GtkCssProvider @@ -2997,44 +3041,8 @@ _gtk_css_provider_load_named (GtkCssProvider *provider, } g_free (resource_path); - - /* Next try looking for files in the various theme directories. - */ - if (variant) - subpath = g_strdup_printf ("gtk-3.0" G_DIR_SEPARATOR_S "gtk-%s.css", variant); - else - subpath = g_strdup ("gtk-3.0" G_DIR_SEPARATOR_S "gtk.css"); - - /* First look in the user's config directory - */ - path = g_build_filename (g_get_user_data_dir (), "themes", name, subpath, NULL); - if (!g_file_test (path, G_FILE_TEST_EXISTS)) - { - g_free (path); - /* Next look in the user's home directory - */ - path = g_build_filename (g_get_home_dir (), ".themes", name, subpath, NULL); - if (!g_file_test (path, G_FILE_TEST_EXISTS)) - { - gchar *theme_dir; - - g_free (path); - - /* Finally, try in the default theme directory */ - theme_dir = _gtk_css_provider_get_theme_dir (); - path = g_build_filename (theme_dir, name, subpath, NULL); - g_free (theme_dir); - - if (!g_file_test (path, G_FILE_TEST_EXISTS)) - { - g_free (path); - path = NULL; - } - } - } - - g_free (subpath); - + /* Next try looking for files in the various theme directories. */ + path = _gtk_css_find_theme (name, variant); if (path) { char *dir, *resource_file; -- 2.30.2